<template>
  <el-container class="home-container">
    <!-- 头部区域 -->
    <el-header>
      <div>
        <div class="head-left button">汽车电子检测中心管理系统</div>
      </div>
      <div class="head-right">
        <img
          src="/IE_MES/notebook/notebook_files/avatar.jpg"
        />
        <el-col :span="24">
          <el-dropdown trigger="click">
            <span class="el-dropdown-link">
              admin<i class="el-icon-caret-bottom"></i>
            </span>
            <template #dropdown>
              <el-dropdown-menuv>
                <el-dropdown-item
                  icon="el-icon-plus"
                  @click="logout"
                  style="width: 80px"
                  >切换站点</el-dropdown-item
                >
                <el-dropdown-item icon="el-icon-circle-plus" @click="logout"
                  >注销</el-dropdown-item
                >
              </el-dropdown-menuv>
            </template>
          </el-dropdown>
        </el-col>
      </div>
    </el-header>
    <!-- 页面主体 -->
    <el-container>
      <!-- 侧边栏 -->
      <el-aside width="220px">
        <!-- 侧边栏菜单 -->
        <el-menu
          background-color="#333744"
          text-color="#fff"
          active-text-color="#409Eff"
          unique-opened="ture"
          router="true"
          :default-active="activePath"
        >
          <!-- 一级菜单 -->
          <el-submenu
            :index="'/' + item.resKey"
            v-for="item in menulist"
            :key="item.id"
          >
            <!-- 一级菜单的模板 -->
            <template #title>
              <i :class="item.icon"></i>
              <span class="button">{{ item.name }}</span>
            </template>
            <!-- 二级菜单 -->
            <el-menu-item
              :index="'/' + subItem.resKey"
              v-for="subItem in item.children"
              :key="subItem.id"
              @click="saveNavState('/' + subItem.resKey)"
            >
              <template #title>
                <!-- <i :class="subItem.icon"></i> -->
                <span class="button">{{ subItem.name }}</span>
              </template>
            </el-menu-item>
          </el-submenu>
        </el-menu>
      </el-aside>
      <!-- 右侧内容 -->
      <el-main>
        <!-- 路由占位符 -->
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
export default {
  data() {
    return {
      menulist: [],
      // 被激活的链接地址
      activePath: "",
    };
  },
  created() {
    this.activePath = window.sessionStorage.getItem("activePath");
    this.getmeal();
  },
  methods: {
    logout() {
      let formdata = new FormData();
      this.$axios({
        headers: {
          "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
        },
        method: "get",
        url: "/IE_MES/logout.shtml",
        data: formdata,
      }).then((res) => {
        console.log(res);
        if (res.data == "success") {
          this.$message.success("退出成功");
          this.$router.push("/login");
        } else {
          this.$message("错误类型:" + res.data);
        }
      });
    },
    saveNavState(activePath) {
      window.sessionStorage.setItem("activePath", activePath);
      this.activePath = activePath;
    },
    getmeal() {
      this.$axios({
        headers: {
          "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
        },
        method: "post",
        url: "/IE_MES/index.shtml",
      }).then((res) => {
        console.log(res.data);
        this.menulist = res.data.list;
      });
    },
  },
};
</script>

<style lang="less" scoped>
.home-container {
  height: 100%;
}
.el-header {
  background-color: #25313e;
  display: flex;
  justify-content: space-between;
  padding-left: 0;
  align-items: center;
  color: #adbece;
  font-size: 20px;
  > div {
    display: flex;
    align-items: center;
    line-height: 60px;
    .head-left {
      margin-left: 30px;
      font-weight: 900;
    }
    .head-left:hover {
      color: white;
      cursor: pointer;
      font-weight: 1000;
    }
    img {
      width: 30px;
      height: 30px;
      border-radius: 50%;
      margin-top: 5px;
    }
  }
}
// 头部下拉框样式
.el-dropdown-link {
  cursor: pointer;
  color: #adbece;
}
.el-dropdown-link:hover {
  color: white;
  cursor: pointer;
}
.el-icon-arrow-down {
  font-size: 12px;
}
.demonstration {
  display: block;
  color: #8492a6;
  font-size: 14px;
  margin-bottom: 20px;
}
// 侧边栏
.el-aside {
  background-color: #333744;
  .el-menu {
    border-right: none;
  }
}
// 主题内容
.el-main {
  background-color: #eaedf1;
}
// 设置文字不可选择
.button {
  display: inline-block;
  -moz-user-select: none;
  -ms-user-select: none;
  -webkit-user-select: none;
  user-select: none;
}
</style>
